package com.test.jfreechart;

import java.awt.Font;
import java.io.*;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;

public class JFreeChartTest3 {

	public static void main(String[] args) throws Exception 
	{
		JFreeChart chart = ChartFactory.createPieChart("human resourse",getDataset(),
				true,false,false);
		chart.setTitle(new TextTitle("human resource", new Font("黑体", 
				Font.BOLD+ Font.ITALIC,20)));
		LegendTitle legend = chart.getLegend(0);
		legend.setItemFont(new Font("黑体",Font.BOLD,15));
		PiePlot plot = (PiePlot)chart.getPlot();
		plot.setLabelFont(new Font("黑体",Font.BOLD,18));
		
		
		OutputStream os = new FileOutputStream("human_res.jpg");
		ChartUtilities.writeChartAsJPEG(os, chart, 1000, 800);
		os.close();
	}
private static DefaultPieDataset getDataset(){
	   DefaultPieDataset dpd = new DefaultPieDataset();
	   dpd.setValue("manager", 25);
		dpd.setValue("sales", 25);
		dpd.setValue("developer", 45);
		dpd.setValue("others", 10);
		return dpd;
   }
}
